package com.mcptt.config.user.profile.sub.sub;

import java.util.List;

import org.jdom.Element;
import org.jdom.JDOMException;

import com.cloudptt.api.comm.CheckData;
import com.cloudptt.api.product.log.Log;
import com.mcptt.config.user.profile.sub.sub.sub.EmergencyAlert;
import com.mcptt.config.user.profile.sub.sub.sub.EmergencyCall;
import com.mcptt.config.user.profile.sub.sub.sub.ImminentPerilCall;

public class McpttGroupCall {
	
	public static final String Name = "MCPTT-group-call";
	private static final String Name_MaxSimultaneousCallsN6 = "MaxSimultaneousCallsN6";
	private static final String Name_Priority = "Priority";
	
	private int maxSimultaneousCallsN6 = 0;
	private int priority = 0;
	private EmergencyCall emergencyCall = null;
	private ImminentPerilCall imminentPerilCall = null;
	private EmergencyAlert emergencyAlert = null;
	
	public void parse(Element elem) throws JDOMException
	{
		if(elem == null)
		{
			return;
		}
		List<Element> list = elem.getChildren();//��ø��ڵ���ӽڵ�  
		for(Element subElem:list) 
		{
			String name = subElem.getName();
			Log.debug(this.getClass(), "name = " + name);
			
			if(name == null
					|| name.length() <= 0)
			{
				return;
			}
			if(name.equals(Name_MaxSimultaneousCallsN6))
			{
				String value = subElem.getText();
				maxSimultaneousCallsN6 = CheckData.parseInt(value);
			}
			else if(name.equals(EmergencyCall.Name))
			{
				emergencyCall = new EmergencyCall();
				emergencyCall.parse(subElem);
			}
			else if(name.equals(ImminentPerilCall.Name))
			{
				imminentPerilCall = new ImminentPerilCall();
				imminentPerilCall.parse(subElem);
			}
			else if(name.equals(EmergencyAlert.Name))
			{
				emergencyAlert = new EmergencyAlert();
				emergencyAlert.parse(subElem);
			}
			else if(name.equals(Name_Priority))
			{
				String value = subElem.getText();
				priority = CheckData.parseInt(value);
			}
		}  
	}
	
	public String toString()
	{
		StringBuffer strBuf = new StringBuffer("\r\n");
		strBuf.append("<").append(Name).append(">").append("\r\n");
		
		strBuf.append("    ").append("<").append(Name_MaxSimultaneousCallsN6).append(">");
		strBuf.append(maxSimultaneousCallsN6);
		strBuf.append("</").append(Name_MaxSimultaneousCallsN6).append(">").append("\r\n");
		
		strBuf.append(emergencyCall);
		strBuf.append(imminentPerilCall);
		strBuf.append(emergencyAlert);
		
		strBuf.append("    ").append("<").append(Name_Priority).append(">");
		strBuf.append(priority);
		strBuf.append("</").append(Name_Priority).append(">").append("\r\n");
		
		strBuf.append("</").append(Name).append(">").append("\r\n");

		return strBuf.toString();
	}
}
